class Register{
    constructor(){
        this.form = $('#registerForm')
        this.userName = $('#userName')
        this.pwd1 = $('#pwd1')
        this.pwd2 = $('#pwd2')
        this.btnSubmit = $('#btnSubmit')
        this.clickSubmit()
        // this.blurEvent()
    }
    clickSubmit(){
        this.btnSubmit.on('click',(e)=>{
            e.preventDefault()
            const userNameValue = this.userName.val()
            const pwd1Value = this.pwd1.val()
            const pwd1Value2 = this.pwd2.val()
            if(pwd1Value !== pwd1Value2){
                alert('两次密码不一致')
            }else if(!userNameValue.trim()){
                alert('账号不能为空')
            }else{
                $.post("/api/user/register", {
                    userName:userNameValue,
                    pwd:pwd1Value
                },function(resp){
                    console.log(resp.data.user)
                    if(resp.code === 200){
                        alert(resp.data.msg + ',即将跳转登录')
                        window.location.href = '/login.html'
                    }else{
                        alert(resp.data.msg)
                    }
                })
            }
        })
    }
}
new Register()